using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace GameVuTru.ManagerScreens
{
    public class CSprite
    {
        public Texture2D texturesprite;
        public Rectangle bound;
        public int currentsprite, totalsprite, columnsprite, widthsprite, heightsprite;
        float timer;
        public CSprite()
        {
        }
        public CSprite(Texture2D text, int total, int colum, int widthtext, int heighttext)
        {
            texturesprite = text;
            currentsprite = 0;
            columnsprite = colum;
            totalsprite = total;
            widthsprite = widthtext / colum;
            heightsprite = heighttext / (total / colum);
            timer = 0;
        }

        public void PositionSprite()
        {
            bound = new Rectangle((currentsprite % columnsprite) * widthsprite, (currentsprite / columnsprite) * heightsprite, widthsprite, heightsprite);
        }
        public void UpdateSprite()
        {
            PositionSprite();
        }
        public void UpdateSprite(GameTime gametime, int begin, int end, int flag)
        {
            timer += (float)gametime.ElapsedGameTime.TotalMilliseconds;
            if (timer >= 33f)
            {
                timer = 0;
                if (flag == -1)
                {
                    currentsprite--;
                    if (currentsprite < begin)
                    {
                        currentsprite = end;
                    }
                    if (currentsprite > end)
                    {
                        currentsprite = end;
                    }
                }
                if (flag == 1)
                {
                    currentsprite++;
                    if (currentsprite < begin)
                    {
                        currentsprite = begin;
                    }
                    if (currentsprite > end)
                    {
                        currentsprite = begin;
                    }
                }
                PositionSprite();
            }
        }

        public void UpdateSprite(float timeamination, GameTime gametime, int begin, int end, int flag)
        {
            timer += (float)gametime.ElapsedGameTime.TotalMilliseconds;
            if (timer >= timeamination)
            {
                timer = 0;
                if (flag == -1)
                {
                    currentsprite--;
                    if (currentsprite < begin)
                    {
                        currentsprite = end;
                    }
                    if (currentsprite > end)
                    {
                        currentsprite = end;
                    }
                }
                if (flag == 1)
                {
                    currentsprite++;
                    if (currentsprite < begin)
                    {
                        currentsprite = begin;
                    }
                    if (currentsprite > end)
                    {
                        currentsprite = begin;
                    }
                }
                PositionSprite();
            }
        }
        public void DrawSprite(SpriteBatch sp, Vector2 pos)
        {
            sp.Draw(texturesprite, pos, bound, Color.White, 0f, new Vector2(bound.Width / 2, bound.Height / 2), 1.0f, SpriteEffects.None, 0);
        }
        public void DrawSprite(SpriteBatch sp, Vector2 pos, float rotation)
        {
            sp.Draw(texturesprite, pos, bound, Color.White, rotation, new Vector2(bound.Width / 2, bound.Height / 2), 1.0f, SpriteEffects.None, 0);
        }
        public void DrawSprite(SpriteBatch sp, float scale, Vector2 pos)
        {
            sp.Draw(texturesprite, pos, bound, Color.White, 0f, new Vector2(bound.Width / 2, bound.Height / 2), scale, SpriteEffects.None, 0);
        }
    }
}
